package com.briup.app02.web.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.briup.app02.bean.Comment;
import com.briup.app02.service.ICommentService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="评论管理")
@Validated
@RestController
@RequestMapping("/Comment")
public class CommentController<commentService> {
	
	@Autowired
	private ICommentService commentService;
	
	@ApiOperation(value="根据id删除评论")
	@GetMapping("deleteById")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value = "id",paramType = "query",required=true)
	})
	public Message deleteById(Long id) {
		commentService.deleteById(id);
		return MessageUtil.success("删除成功");
	}
	
	@ApiOperation(value = "审核评论")
	@GetMapping("check")
	public Message check(Long id, String status) {
		commentService.check(id, status);
		return MessageUtil.success("审核完毕");
	}
	
	
	@ApiOperation(value="保存或更新评论")
	@ApiImplicitParams({@ApiImplicitParam(name="id",value = "id",paramType = "form"),})
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(Comment comment) {
		commentService.saveOrUpdate(comment);
		return MessageUtil.success("更新成功");
	}
	
	
	
	@ApiOperation(value="批量删除全部评论")
	@GetMapping("batchDelete")
	public Message batchDelete(@RequestParam(value ="id")List<Long> id) {
		commentService.batchDelete(id);
		return MessageUtil.success("删除成功");
	}
	
	@ApiOperation(value="查询所有评论")
	@GetMapping("query")
	public Message query(String comment,String status){
		List<Comment> list = commentService.query(comment,status);
		return MessageUtil.success(list);
	}
}
